Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ListBurns RPC #1178

Merged
merged 6 commits into from
Nov 26, 2024
Merged

Add ListBurns RPC #1178

merged 6 commits into from
Nov 26, 2024

Conversation

GeorgeTsagk
Copy link
Member

Description

We're currently able to provably burn assets with tapd but we have no (easy) way of retrieving burn related historical data. This PR adds a DB table and exposes some new RPC methods/parameters to help keep track of burns.

When completing an asset burn, we add an entry to the new burns table. We also add a new ListBurns method which returns a list of all burns that pass the user-provided filters (asset id, group id, anchor txid)

Closes #1095

@coveralls
Copy link

coveralls commented Nov 7, 2024

Pull Request Test Coverage Report for Build 12038238720

Details

  • 61 of 172 (35.47%) changed or added relevant lines in 6 files are covered.
  • 24 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.02%) to 40.836%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapfreighter/parcel.go 0 3 0.0%
tapdb/sqlc/transfers.sql.go 30 38 78.95%
tapdb/assets_store.go 31 49 63.27%
tapfreighter/chain_porter.go 0 22 0.0%
rpcserver.go 0 28 0.0%
cmd/tapcli/assets.go 0 32 0.0%
Files with Coverage Reduction New Missed Lines %
tappsbt/create.go 2 53.22%
tapchannel/aux_leaf_signer.go 3 36.31%
asset/mock.go 3 92.2%
asset/asset.go 4 80.96%
tapdb/multiverse.go 6 68.21%
commitment/tap.go 6 83.91%
Totals Coverage Status
Change from base Build 12037803959: -0.02%
Covered Lines: 25706
Relevant Lines: 62950

💛 - Coveralls

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. I wonder if we should add a Golang based "migration" of sort that queries existing assets in the DB, checks if they're burns (cannot be done on SQL level alone) and then inserts them into the new table retroactively?
Perhaps we could add a mechanism that detects if any DB level migrations were executed. And if they were, we can assume an update happened and could run these Golang-level checks (which would need to be idempotent).

tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
taprpc/taprootassets.proto Show resolved Hide resolved
taprpc/taprootassets.yaml Outdated Show resolved Hide resolved
cmd/tapcli/assets.go Outdated Show resolved Hide resolved
cmd/tapcli/assets.go Outdated Show resolved Hide resolved
tapdb/sqlc/queries/transfers.sql Show resolved Hide resolved
@dstadulis dstadulis added this to the v0.5 (v0.4.2 rename) milestone Nov 11, 2024
@GeorgeTsagk GeorgeTsagk force-pushed the track-burns branch 3 times, most recently from 7f7febe to ba5db4b Compare November 13, 2024 11:26
@GeorgeTsagk GeorgeTsagk requested a review from guggero November 13, 2024 11:32
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super close!

tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/sqlc/queries/transfers.sql Outdated Show resolved Hide resolved
tapdb/sqlc/queries/transfers.sql Show resolved Hide resolved
tapdb/assets_store_test.go Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
cmd/tapcli/assets.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef requested review from Roasbeef and removed request for ffranr November 14, 2024 03:00
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapdb/assets_store_test.go Show resolved Hide resolved
tapdb/sqlc/queries/transfers.sql Show resolved Hide resolved
rpcserver.go Outdated
@@ -3312,12 +3314,56 @@ func (r *rpcServer) BurnAsset(ctx context.Context,
}
}

// At this point everything completed correctly, so we log this burn in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, perhaps we should do this further in the pipeline? So in the same db transaction that we insert the transfer.

Otherwise, if we crash here, then the burn is never inserted in the db, and we exit in an inconsistent state.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems to happen within the state machine of the chain porter, deep in the r.cfg.ChainPorter.RequestShipment step above

threading through all the params needed for the InsertBurn call seems like a bad way to go

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

threading through all the params needed for the InsertBurn call seems like a bad way to go

Can you think of an alternative?

We want this visibility to be air tight. If it's possible to just not record a burn all together, then that's problematic.

Perhaps we need a hybrid migration route where we scan the db to insert the new burn metadata into transfers, then can rely on that information being specified in a transfer?

Can you explain the issue you see with adding this meta data at the transfers level to it can be inserted when we go to log the parcel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like most of the burn info is available in the Parcel itself, so with the latest push I"m inserting the Burn in the same transaction as the transfer.

Only needed to add the note string argument as an extra to some interfaces, but it's minimal

rpcserver.go Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
@GeorgeTsagk GeorgeTsagk force-pushed the track-burns branch 2 times, most recently from 765a010 to b9334f1 Compare November 22, 2024 12:17
@bhandras
Copy link
Member

bhandras commented Nov 22, 2024

Looks pretty good. I wonder if we should add a Golang based "migration" of sort that queries existing assets in the DB, checks if they're burns (cannot be done on SQL level alone) and then inserts them into the new table retroactively? Perhaps we could add a mechanism that detects if any DB level migrations were executed. And if they were, we can assume an update happened and could run these Golang-level checks (which would need to be idempotent).

Just saw this comment, and thought this might come in handy: lightningnetwork/lnd@fba2b5d

(Second commit from the WIP PR lightningnetwork/lnd#8831)

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM 🎉

tapdb/sqlc/queries/transfers.sql Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapfreighter/chain_porter.go Outdated Show resolved Hide resolved
tapdb/assets_store.go Outdated Show resolved Hide resolved
tapfreighter/parcel.go Outdated Show resolved Hide resolved
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👟

@GeorgeTsagk GeorgeTsagk force-pushed the track-burns branch 2 times, most recently from 8777a20 to fdcd795 Compare November 26, 2024 19:55
@GeorgeTsagk
Copy link
Member Author

rebased, waiting CI then merging

@guggero guggero merged commit f35de11 into lightninglabs:main Nov 26, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

tapdb - [feature]: add new associative table to track asset burns ListBurns
6 participants